package com.oa.modules.approvalsec1.service.impl;

import com.oa.common.utils.AppUtils;
import com.oa.common.utils.Constant;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.Query;
import com.oa.modules.approvalsec1.socket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.oa.modules.approvalsec1.dao.NewsNoticeDao;
import com.oa.modules.approvalsec1.entity.NewsNoticeEntity;
import com.oa.modules.approvalsec1.service.NewsNoticeService;


@Service("newsNoticeService")
public class NewsNoticeServiceImpl extends ServiceImpl<NewsNoticeDao, NewsNoticeEntity> implements NewsNoticeService {

    @Autowired
    private NewsNoticeService newsNoticeService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        params.put("status", Constant.YES_OR_NO.YES.getValue());
        IPage page= AppUtils.getPage(new Query<NewsNoticeEntity>(), params);
        return AppUtils.setPage(page, baseMapper.findPage(params), baseMapper.findRecords(page, params));
    }

    @Override
    public void pushToWeb() {
        try {
            List<NewsNoticeEntity> noticeEntityList = newsNoticeService.queryNotices();
            WebSocketServer.sendInfo(noticeEntityList);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public List<NewsNoticeEntity> queryNotices(){
        return baseMapper.queryNotices();
    }
}
